package Stack_Queue;

import java.util.Stack;

public class 删除字符串中的所有相邻重复项 {
    public String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()) {
            if (!stack.empty() && stack.peek() == c) stack.pop();
            else stack.push(c);
        }
        StringBuffer str = new StringBuffer();
        while (!stack.empty()) str.append(stack.pop());
        return str.reverse().toString();
    }
}
